package com.wiz.weixin.controllor;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

import org.json.JSONException;
import org.json.JSONObject;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.wiz.weixin.common.ResponseCode;
import com.wiz.weixin.manager.CardManager;
@Controller
@RequestMapping("/card")
public class CardControllor implements ResponseCode{
	private transient final Logger log=LoggerFactory.getLogger(getClass());
	@Resource
	private CardManager cardManager;
	/**创建会员卡*/
	@RequestMapping(value="/createMember")
	@ResponseBody
	public String createMember(HttpServletRequest request,HttpServletResponse response,
			HttpSession session, Model model) throws JSONException {
		
		if(cardManager.createMember()){
			return "success";
		}
		return "fail";
		
	}
	/**生成会员卡二维码*/
	@RequestMapping(value="/memberCode")
	public String memberCode(HttpServletRequest request,HttpServletResponse response,
			HttpSession session, Model model) throws JSONException {

		try {
			JSONObject responseJson = cardManager.memberCode();
			String show_qrcode_url  = responseJson.getString("show_qrcode_url");
			return "redirect:"+show_qrcode_url;
		} catch (Exception e) {
			e.printStackTrace();
			log.error(e.getMessage());
		}
		return null; 
		
	}
}
